<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/9/21
 * Time: 15:55
 */

namespace App\HttpController\Home;

use App\Enums\UrlEnums;
use App\Library\Auth;
use EasySwoole\HttpClient\HttpClient;

class Csgo extends Base
{
    /**
     * 文字直播
     */
    public function wordLive()
    {
        $match_id = $this->request()->getQueryParam('match_id');
        if( !$match_id ){
            return $this->writeJson(0,null,'缺少match_id参数');
        }
        list($s1, $s2) = explode(' ', microtime());
        $microtime = (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000); //毫秒时间戳
        $url = UrlEnums::FJURL.UrlEnums::CSGO_BATTLE_LOG."?match_id={$match_id}";
        $client = new HttpClient($url);
        $option = [
            'path'      => UrlEnums::CSGO_BATTLE_LOG,
            'api_time'  => $microtime
        ];
        $header = Auth::getInstance()->header($option);
        $client->setHeaders($header,true,false);
        $response = $client->get();
        $content = $response->getBody();
        $data = json_decode($content,true);
        if( isset($data['code']) && $data['code'] == 200 && $data['data'] ){
            return $this->writeJson(1,$data['data'],'请求成功');
        }else{
            return $this->writeJson(0,null,$data['message']);
        }
    }
}